import Vue from 'vue'
import store from './store'
import App from './App'
import Http from './config/http.js'
import Json from './Json' //测试用数据

import 'static/css/common.scss'
import * as Common from 'config/common.js'

Vue.prototype.$common = Common;

// 
Vue.prototype.$http = Http;
Vue.prototype.$gwx = Http;

Vue.prototype.$format = (val) => { // 处理金额
	let str = val.toFixed(2) + '';
	let intSum = str.substring(0, str.indexOf(".")).replace(/\B(?=(?:\d{3})+$)/g, ',');
	let dot = str.substring(str.length, str.indexOf("."));
	let ret = intSum + dot;
	return ret;
}

Vue.prototype.$cityName = function(key){
		var userInfo =  uni.getStorageSync(key);
		console.log('main:' + userInfo)
	if (userInfo != null && userInfo != "" && userInfo != undefined) {
		return userInfo;
	}else{
		return "请选择";
	}
}

const msg = (title, duration=1500, mask=false, icon='none')=>{
	//统一提示方便全局修改
	if(Boolean(title) === false){
		return;
	}
	uni.showToast({
		title,
		duration,
		mask,
		icon
	});
}
const json = type=>{
	//模拟异步请求数据
	return new Promise(resolve=>{
		setTimeout(()=>{
			resolve(Json[type]);
		}, 500)
	})
}
const prePage = ()=>{
	let pages = getCurrentPages();
	let prePage = pages[pages.length - 2];
	// #ifdef H5
	return prePage;
	// #endif
	return prePage.$vm;
}


Vue.config.productionTip = false
Vue.prototype.$fire = new Vue();
Vue.prototype.$store = store;
Vue.prototype.$api = {msg, json, prePage};

App.mpType = 'app'

const app = new Vue({
    ...App
})
app.$mount()